<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8">
            <a-form-model-item label="时间" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="date">
              <g-year-picker
                placeholder="请选择时间"
                v-model="model.date"
              ></g-year-picker>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amount">
              <a-input-number v-model="model.amount" placeholder="请输入金额/万" style="width: 100%" @blur="getTotalScore" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="总分" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="totalScore">
              <a-input-number v-model="model.totalScore" placeholder="请输入总分" style="width: 100%" :disabled="true" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="课题名称" :labelCol="{ span: 2 }" :wrapperCol="{ span: 22 }" prop="projectName">
              <a-input v-model="model.projectName" placeholder="请输入课题名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="{ span: 2 }" :wrapperCol="{ span: 22 }" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
    <!-- 子表单区域 -->
    <research-member-list ref="memberListRef" v-model="memberListTable.dataSource" :project-info="model"
                          :disabled="formDisabled" :loading="memberListTable.loading"></research-member-list>
  </a-spin>
</template>

<script>

import { getAction } from '@/api/manage'
import { GfxyResearchMemberListMixin } from '@/mixins/GfxyResearchMemberListMixin'
import GYearPicker from '@views/gfxy/common/GYearPicker'
import researchMemberList from '@views/gfxy/common/researchMemberList'

export default {
  name: 'ResearchHxktForm',
  mixins: [GfxyResearchMemberListMixin],
  components: {
    GYearPicker, researchMemberList
  },
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 3 }
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 20 }
      },
      model: {},
      validatorRules: {
        date: [
          { required: true, message: '请输入时间!' }
        ],
        amount: [
          { required: true, message: '请输入金额!' }
        ],
        projectName: [
          { required: true, message: '请输入课题名称!' }
        ]
      },
      url: {
        add: '/research/researchHxkt/add',
        edit: '/research/researchHxkt/edit',
        queryById: '/research/researchHxkt/queryById',
        getTotalScore: '/research/researchHxkt/getTotalScore'
      }
    }
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    },
    projectType: {
      type: Number,
      required: true
    },
    date: {
      type: String,
      required: true
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
  },
  methods: {
    getTotalScore() {
      let that = this
      if (this.model.amount != undefined) {
        this.confirmLoading = true
        getAction(this.url.getTotalScore, { amount: this.model.amount }).then((res) => {
          if (res.success) {
            this.model.totalScore = res.result
            this.$nextTick(() => {
              this.$refs.memberListRef.getScore()
            })
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }

        }).catch(() => {
          this.$message.warning('出错！')
        }).finally(() => {
          this.confirmLoading = false
        })
      }
    }
  }
}
</script>

<style scoped>
</style>